﻿using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using YY.Admin.Core;
using YY.Admin.Services.Service.User;

namespace YY.Admin.ViewModels
{
    public class StatisticCard
    {
        public string Title { get; set; } = string.Empty;
        public string Value { get; set; } = string.Empty;
        public string Icon { get; set; } = string.Empty;
        public string Color { get; set; } = string.Empty;
        public string Trend { get; set; } = string.Empty;
    }

    public class RecentActivity
    {
        public string Title { get; set; } = string.Empty;
        public string Description { get; set; } = string.Empty;
        public DateTime Time { get; set; }
        public string Icon { get; set; } = string.Empty;
    }

    public class DashboardViewModel : BaseViewModel
    {
        private readonly ISysUserService _userService;

        public DashboardViewModel(
            ISysUserService userService,
            IContainerExtension _container
            ) : base(_container)
        {
          //  _eventAggregator.GetEvent<ThemeChangedEvent>().Subscribe(ApplyTheme);
            _userService = userService;
            Title = "仪表盘";
            LoadDashboardDataAsync();
        }

        public ObservableCollection<StatisticCard> StatisticCards { get; } = new();
        public ObservableCollection<RecentActivity> RecentActivities { get; } = new();

        private async Task LoadDashboardDataAsync()
        {
            IsLoading = true;

            try
            {
                // 加载统计数据
                var users = await _userService.GetUsersAsync();

                StatisticCards.Clear();
                StatisticCards.Add(new StatisticCard
                {
                    Title = "总用户数",
                    Value = users.Count.ToString(),
                    Icon = "UserOutlined",
                    Color = "#1890ff",
                    Trend = "+12%"
                });
                StatisticCards.Add(new StatisticCard
                {
                    Title = "活跃用户",
                    Value = users.Count(u => u.Status== StatusEnum.Enable).ToString(),
                    Icon = "UserCheckOutlined",
                    Color = "#52c41a",
                    Trend = "+8%"
                });
                StatisticCards.Add(new StatisticCard
                {
                    Title = "今日访问",
                    Value = "1,234",
                    Icon = "EyeOutlined",
                    Color = "#faad14",
                    Trend = "+5%"
                });
                StatisticCards.Add(new StatisticCard
                {
                    Title = "系统消息",
                    Value = "56",
                    Icon = "MessageOutlined",
                    Color = "#f5222d",
                    Trend = "+2"
                });

                // 加载最近活动
                RecentActivities.Clear();
                RecentActivities.Add(new RecentActivity
                {
                    Title = "用户登录",
                    Description = "管理员 admin 登录系统",
                    Time = DateTime.Now.AddMinutes(-5),
                    Icon = "LoginOutlined"
                });
                RecentActivities.Add(new RecentActivity
                {
                    Title = "数据更新",
                    Description = "用户数据已同步更新",
                    Time = DateTime.Now.AddMinutes(-15),
                    Icon = "SyncOutlined"
                });
                RecentActivities.Add(new RecentActivity
                {
                    Title = "系统备份",
                    Description = "数据库备份已完成",
                    Time = DateTime.Now.AddHours(-2),
                    Icon = "DatabaseOutlined"
                });
            }
            finally
            {
                IsLoading = false;
            }
        }
     
    }
}
